/**
 * @file models/marketData.js
 * @author
 */

import { routerRedux } from 'dva/router';
import api from '../api';
import { delay } from '../utils/sagaEffects';

export default {
  namespace: 'marketData',
  state: {
    klineData: null,
    tickData: null,
    kline1min: null,
  },
  reducers: {
    getKlineDataSuccess(state, action) {
      const { payload: { response } } = action;
      const { list } = response.data;
      return {
        ...state,
        klineData: response.data,
      };
    },
    getKline1minSuccess(state, action) {
      const { payload: { response } } = action;
      const { list } = response.data;
      return {
        ...state,
        kline1min: response.data,
      };
    },
    getTickDataSuccess(state, action) {
      const { payload: { response } } = action;
      const { list } = response.data;
      return {
        ...state,
        tickData: response.data,
      };
    },
  },
  effects: {
    * getKlineData({ payload: query }, { call, put }) {
      const response = yield call(api.getKlineData, query);
      yield put({
        type: 'getKlineDataSuccess',
        payload: { response },
      });
    },
    * getKline1min({ payload: query }, { call, put }) {
      const response = yield call(api.getKline1min, query);
      yield put({
        type: 'getKline1minSuccess',
        payload: { response },
      });
    },
    * getTickData({ payload: query }, { call, put }) {
      const response = yield call(api.getTickData, query);
      yield put({
        type: 'getTickDataSuccess',
        payload: { response },
      });
    },
  },
  subscriptions: {},
};
